﻿namespace AC.ExtendedRenderer.Toolkit.Charting
{
    using ComponentFactory.Krypton.Toolkit;
    using System;
    using System.Windows.Forms;

    public class KryptonAquaGauge : AquaGauge
    {
        private IPalette _palette;
        private PaletteRedirect _paletteRedirect;

        public KryptonAquaGauge()
        {
            base.SetStyle(ControlStyles.UserPaint, true);
            base.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
            base.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
            base.UpdateStyles();
            if (this._palette != null)
            {
                this._palette.PalettePaint += new EventHandler<PaletteLayoutEventArgs>(this.OnPalettePaint);
            }
            KryptonManager.GlobalPaletteChanged += new EventHandler(this.OnGlobalPaletteChanged);
            this._palette = KryptonManager.CurrentGlobalPalette;
            this._paletteRedirect = new PaletteRedirect(this._palette);
            this.InitColors();
        }

        private void InitColors()
        {
            base.DialColor = this._palette.ColorTable.ToolStripGradientBegin;
            this.ForeColor = this._palette.ColorTable.StatusStripText;
            base.DigitColor = this._palette.ColorTable.StatusStripText;
        }

        private void OnGlobalPaletteChanged(object sender, EventArgs e)
        {
            if (this._palette != null)
            {
                this._palette.PalettePaint -= new EventHandler<PaletteLayoutEventArgs>(this.OnPalettePaint);
            }
            this._palette = KryptonManager.CurrentGlobalPalette;
            this._paletteRedirect.Target = this._palette;
            if (this._palette != null)
            {
                this._palette.PalettePaint += new EventHandler<PaletteLayoutEventArgs>(this.OnPalettePaint);
                this.InitColors();
            }
            base.Invalidate();
        }

        private void OnPalettePaint(object sender, PaletteLayoutEventArgs e)
        {
            base.Invalidate();
        }
    }
}

